package com.ithuangyl.home;

import android.util.Log;
import android.view.View;

import androidx.annotation.NonNull;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.ithuangyl.annotation.BindPath;
import com.ithuangyl.common.base.BaseListActivity;
import com.ithuangyl.common.mvp.factory.CreatePresenter;

import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;

@CreatePresenter(TestListPresenter.class)
@BindPath("activity/list-test")
public class ListTestActivity extends BaseListActivity<String, TestListView, TestListPresenter> implements TestListView {

    @Override
    protected BaseQuickAdapter<String, BaseViewHolder> setAdapter() {

        return new BaseQuickAdapter<String, BaseViewHolder>(R.layout.item_list_test) {
            @Override
            protected void convert(@NotNull BaseViewHolder holder, String s) {
                holder.setText(R.id.id_text, s);
            }
        };
    }

    @Override
    protected void requestData(int pageIndex) {
        getPresenter().getList(pageIndex);
    }

    @Override
    protected void initViewed() {
        setStatusBarView(R.drawable.shape_main_bar_bg);
        statusBarDarkFont(false, 1.0f);
        vTopBar.title("列表测试页", R.color.white, null)
                .showLeftIcon(false)
                .setBackgroundResource(R.drawable.shape_main_bar_bg);
        mAdapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
                Log.e("tag", (position % 2 == 0) + "");
                setEnableLoadMore(position % 2 == 0);
            }
        });
    }


    @Override
    public void getViewSuccess(VersionInfo info) {
        finishRequest();
        List<String> list = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            list.add(i + "");
        }
        handlerListData(4, list);
        Log.e("TAG", "onSuccess" + info.data.version);
    }

    @Override
    public void getViewFailure(int code, String message) {
        finishRequest();
        Log.e("TAG", "onFailure" + message);
    }
}